<template>
    <div id="loading" v-if="visible" :class="{'absolute':absolute}">
        <div class="loading_container" v-if="visible === 'loading'">
            <img src="static/loading.gif" alt="">
        </div>
        <div class="error_container" v-else-if="visible === 'error'">
            <div class="error_box">
                <p class="error_text">网络出现错误</p>
                <mt-button class="error_btn" type='primary' @click.stop='reload'>重试</mt-button>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        visible: {
            type: [Boolean, String],
            default: false
        },
        reload: Function,
        absolute: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            size: 36,
            color: '#5F88FF'
        }
    }
}
</script>
<style scoped lang='stylus'>
#loading {
    width: 100%;
    height: 100%;
    overflow: hidden;
    
    background-color: #fff;
    z-index: 588;
    &.absolute{
        position: absolute;
        top: 0;
    }
    .loading_container,
    .error_container{
        position: relative;
        width: 100%;
        height: 100%;
        text-align: center;
    }
    .loading_container{
        img{
            width:70px;
            margin:0 auto;
            position:absolute;
            top:50%;
            left:50%;
            transform:translate(-50%,-50%)
        }
    }
    .error_box{
        position: absolute;
        left: 0;
        right: 0;
        top: 30%;
        text-align: center;
        line-height: 30px;
        .error_text {
            color: #aaa;
            margin-bottom: 10px;
            font-size: 16px;
        }
        .error_btn {
            font-size:14px;
            height:30px;
            border-radius: 5px;
            background-color:#5f88ff;
        }
    }
    span {
        position: absolute;
        top: 40%;
        left: 50%;
        margin-left: -18px;
    }
}
</style>
